package 分类.滑动窗口;

import java.util.HashMap;

public class 无重复字符的最长子串 {
    public int lengthOfLongestSubstring(String s) {
        int left=0,right=0;
        int res=0;
        HashMap<Character, Integer> hashMap=new HashMap<>();
        while (right<s.length()){
            char c=s.charAt(right);
            int num=hashMap.getOrDefault(c,0);
            hashMap.put(c,++num);
            right++;
            while (hashMap.getOrDefault(c,0)>1){
              char a=s.charAt(left);
                int num1=hashMap.getOrDefault(a,0);
                hashMap.put(a,--num1);
                left++;
            }
            res=Math.max(res,right-left+1);
        }
        return res;
    }


}
